package jvm;

import java.lang.ref.SoftReference;

/**
 * @Author Stringzhua
 * @Date 2024/11/6 16:14
 * description:
 */
public class Demo04 {
    public static void main(String[] args) {
        //软引用
        String s = new String("abc");
        SoftReference<String> softReference = new SoftReference<>(s);

        s = null;
        //通知gc,回收软引用
        System.gc();

        try {
            byte[] bytes1 = new byte[900000000];
            byte[] bytes2 = new byte[900000000];
            byte[] bytes3 = new byte[900000000];
            byte[] bytes4 = new byte[900000000];
            byte[] bytes5 = new byte[900000000];
        } catch (Exception e) {
            e.printStackTrace();
        }
        //访问软引用
        System.out.println(softReference.get());
    }
}
